#include<bits/stdc++.h>
using namespace std;
int t,n;
struct num{
    int nu;
    int co;
};
num c[200001];
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    int c1,c2,sum=0;
    while(t--){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>c[i].nu;
            c[i].co=0;
        }
        bool f=true;
        while(f){
            int maxx=-1;
            f=false;
            for(int i=1;i<=n;i++){
                for(int j=i+1;j<=n;j++){
                    if(c[i].nu==c[j].nu&&(c[i].co==0&&c[j].co==0)&&c[i].nu>maxx){
                        maxx=c[i].nu;
                        c1=i;
                        c2=j;
                        f=true;
                    }
                }
            }
            if(f){
                c[c1].co=c[c2].co=1;
                sum+=c[c1].nu;
            }
        }
        cout<<sum<<endl;
        sum=0;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
